﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace WinMote7.Helpers
{
    public class QueryStringHelper
    {
        public static Dictionary<string, string> ParseQueryString(string url)
        {
            Dictionary<string, string> results = new Dictionary<string, string>();

            if (url.Contains("?"))
            {
                url = url.Substring(url.IndexOf('?') + 1);
            }

            foreach (string vp in Regex.Split(url, "&"))
            {
                string[] singlePair = Regex.Split(vp, "=");

                if (singlePair.Length == 2)
                {
                    results.Add(singlePair[0], singlePair[1]);
                }
                else
                {
                    results.Add(singlePair[0], string.Empty);
                }
            }

            return results;
        }
    }
}
